package com.panshi.api.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @author :jiege
 * @description :
 * @create :2020-07-09 19:17:00
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {


    @Bean
    public Docket getDocket(Environment environment) {
        //设置要显示的Swagger 环境
        //Profiles profiles= Profiles.of("dev","test");

        //通过environment.acceptsProfiles 判断是否处在自己设定的环境当中
        //boolean flag=environment.acceptsProfiles(profiles);


        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).enable(true).groupName("小五")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.panshi"))//一般使用这个

                //paths() 过滤什么路径
                //.paths(PathSelectors.ant("/ps/**"))
                .build();
    }

    //配置swagger信息=ApiInfo
    private ApiInfo apiInfo(){
        //作者信息
        Contact DEFAULT_CONTACT = new Contact("小五", "", "");
        return new ApiInfo("欢迎来到swagger",
                        "Api Documentation",
                        "1.0",
                        "urn:tos",
                        DEFAULT_CONTACT,
                        "Apache 2.0",
                        "http://www.apache.org/licenses/LICENSE-2.0",
                        new ArrayList());
    }
}
